home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / tabvie / drawview.cpp < prev    next >
C/C++ Source or Header  |  1995-11-01  |  5KB  |  233 lines

  1. // demoview.cpp : implementation of the CDemoView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tab.h"
  6.  
  7. #include "tabdoc.h"
  8. #include "tabview.h"
  9. #include "drawview.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CDrawView
  18. #define BASE CScrollView
  19. #define THIS CDrawView
  20.  
  21. IMPLEMENT_DYNCREATE(CDrawView, CScrollView)
  22.  
  23. BEGIN_MESSAGE_MAP(CDrawView, CScrollView)
  24.     //{{AFX_MSG_MAP(CDrawView)
  25.     ON_WM_LBUTTONDOWN()
  26.     ON_COMMAND(ID_LOOK_CHICAGO, OnLookChicago)
  27.     ON_COMMAND(ID_LOOK_MSWORD, OnLookMsword)
  28.     ON_WM_SYSCOMMAND()
  29.     ON_WM_ERASEBKGND()
  30.     ON_WM_KEYDOWN()
  31.     //}}AFX_MSG_MAP
  32.     // Standard printing commands
  33.     ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  34.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  35. END_MESSAGE_MAP()
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CDrawView construction/destruction
  39.  
  40. THIS::THIS()
  41. {
  42. }
  43.  
  44. THIS::~THIS()
  45. {
  46. }
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CDrawView drawing
  50.  
  51. void THIS::OnDraw(CDC* pDC)
  52. {
  53.     CTabDoc* pDoc = GetDocument();
  54.     CRect rect;
  55.     int x=10,y=10;
  56.     CRect clip,interSect;
  57.     
  58.     pDC->GetClipBox(&clip);
  59.     
  60.     for(int i=0;i<20;i++)
  61.     {
  62.         for(int j=0;j<20;j++)
  63.         {
  64.             rect.SetRect(x,y,x+50,y+50);
  65.             if(interSect.IntersectRect(&rect,&clip))
  66.                 drawButton(pDC,rect,"TAB");
  67.             x += 100;
  68.         }
  69.         if(i % 2)
  70.             x = 10;
  71.         else
  72.             x = 60;
  73.         y += 50;
  74.     }
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CDemoView printing
  79.  
  80. BOOL THIS::OnPreparePrinting(CPrintInfo* pInfo)
  81. {
  82.     // default preparation
  83.     return DoPreparePrinting(pInfo);
  84. }
  85.  
  86. void THIS::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  87. {
  88.     // TODO: add extra initialization before printing
  89. }
  90.  
  91. void THIS::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  92. {
  93.     // TODO: add cleanup after printing
  94. }
  95.  
  96.  
  97.  
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CDemoView diagnostics
  101.  
  102. #ifdef _DEBUG
  103. void THIS::AssertValid() const
  104. {
  105.     CScrollView::AssertValid();
  106. }
  107.  
  108. void THIS::Dump(CDumpContext& dc) const
  109. {
  110.     CScrollView::Dump(dc);
  111. }
  112.  
  113. CTabDoc* THIS::GetDocument() // non-debug version is inline
  114. {
  115.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTabDoc)));
  116.     return (CTabDoc*) m_pDocument;
  117. }
  118.  
  119. #endif //_DEBUG
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CDemoView message handlers
  123.  
  124. void THIS::OnLButtonDown(UINT nFlags, CPoint point)
  125. {
  126.     AfxMessageBox("Mouse is Down in CDrawView object");
  127. }
  128. void THIS::OnInitialUpdate()
  129. {
  130.     CSize size(1500,1500);
  131.     SetScrollSizes(MM_TEXT,size);
  132. }
  133. void THIS::OnSysCommand(UINT nChar,LONG lParam)
  134. {
  135.     if(m_pTabView->doSysCommand(nChar,lParam))
  136.         return;
  137.     BASE::OnSysCommand(nChar,lParam);
  138. }
  139. void THIS::OnLookChicago()
  140. {
  141.     m_pTabView->setLAF(LAF_CHICAGO);
  142. }
  143.  
  144. void THIS::OnLookMsword()
  145. {
  146.     m_pTabView->setLAF(LAF_MSWORD);
  147. }
  148.  
  149. BOOL CDrawView::OnEraseBkgnd(CDC* pDC)
  150. {
  151.     
  152.     CBrush backBrush(RGB(0,0,255));
  153.     CBrush* pOldBrush = pDC->SelectObject(&backBrush);
  154.     
  155.     CRect rect;
  156.     pDC->GetClipBox(&rect);    //erase the area needed
  157.     pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);
  158.     pDC->SelectObject(pOldBrush);
  159.     return TRUE;
  160. }
  161. #define BKPEN()pDC->SelectObject(&blackPen)
  162. #define LTPEN()pDC->SelectObject(&lightPen)
  163. #define DKPEN()pDC->SelectObject(&darkPen)
  164. void    THIS::drawButton(CDC* pDC, CRect rect, char* label)
  165. {
  166.     int oldMode = pDC->SetBkMode(TRANSPARENT);
  167.       COLORREF oldTextColor = pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));
  168.     CPen darkPen(PS_SOLID,0,GetSysColor(COLOR_BTNSHADOW));
  169.     CPen lightPen(PS_SOLID,0,GetSysColor(COLOR_BTNHIGHLIGHT));
  170.     CPen* pOldPen = pDC->SelectObject(&darkPen);
  171. //fill background
  172.     CBrush backBrush(GetSysColor(COLOR_BTNFACE));
  173.     CBrush* pOldBrush = pDC->SelectObject(&backBrush);
  174.     pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);
  175.     pDC->SelectObject(pOldBrush);
  176. //dark
  177.      pDC->MoveTo(rect.left,rect.bottom);
  178.      pDC->LineTo(rect.right,rect.bottom);
  179.      pDC->LineTo(rect.right,rect.top);
  180.  
  181.      pDC->MoveTo(rect.left+1,rect.bottom-1);
  182.      pDC->LineTo(rect.right-1,rect.bottom-1);
  183.      pDC->LineTo(rect.right-1,rect.top+1);
  184. //light
  185.     LTPEN();
  186.      pDC->MoveTo(rect.left,rect.bottom-1);
  187.      pDC->LineTo(rect.left,rect.top);
  188.      pDC->LineTo(rect.right-1,rect.top);
  189.  
  190.      pDC->MoveTo(rect.left+1,rect.bottom-2);
  191.      pDC->LineTo(rect.left+1,rect.top+1);
  192.      pDC->LineTo(rect.right-2,rect.top+1);
  193. //text
  194.     if(label)
  195.         pDC->DrawText(label,-1,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
  196. //cleanup
  197.     pDC->SelectObject(pOldPen);
  198.     pDC->SetTextColor(oldTextColor);
  199.     pDC->SetBkMode(oldMode);
  200. }
  201. void THIS::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  202. {
  203.     switch(nChar)
  204.     {
  205.         case VK_HOME:
  206.             OnScroll(MAKEWORD(SB_TOP,SB_TOP), 0);
  207.             break;
  208.         case VK_END:
  209.             OnScroll(MAKEWORD(-1,SB_BOTTOM), 0);
  210.             break;
  211.         case VK_UP:
  212.             OnScroll(MAKEWORD(-1,SB_LINEUP), 0);
  213.             break;
  214.         case VK_DOWN:
  215.             OnScroll(MAKEWORD(-1,SB_LINEDOWN), 0);
  216.             break;
  217.         case VK_PRIOR:
  218.             OnScroll(MAKEWORD(-1, SB_PAGEUP), 0);
  219.             break;
  220.         case VK_NEXT:
  221.             OnScroll(MAKEWORD(-1, SB_PAGEDOWN), 0);
  222.             break;
  223.         case VK_LEFT:
  224.             OnScroll(MAKEWORD(SB_PAGEUP,-1), 0);
  225.             break;
  226.         case VK_RIGHT:
  227.             OnScroll(MAKEWORD(SB_PAGEDOWN,-1), 0);
  228.             break;
  229.         default:
  230.             break;
  231.     }
  232. }
  233.